package com.dashboard.dto
{
	import com.dashboard.managers.PodLayoutManager;
	import com.dashboard.view.Pod;
	import mx.controls.Alert;
	import mx.core.Application;
	
	public class Personalization
	{
		//Implement the persnolize xml
		public var personlizeXML:XML;
		public static var manager:PodLayoutManager = null;
			//For personalization
	    public static var layoutManagerViewType:String;				//Stores list or grid view
		public static var isFullScreen:Boolean = false;						//Stores the fullscreenview mode
		public static var personalization:XML;                       // set the personalization xml to null by default
	
		public function Personalization()
		{
		}
		
		public static function UpdatePersonalization():void
		{ 
			if (manager == null) return;
			var temp:String = Application.application.ObjConfigaration.isPersonalized;
			if (temp.toLowerCase() == "false")	return;
			personalization = new XML();
			//personalization = <personalization> </personalization>;
			personalization = <personalization> </personalization>;
			var dashboard:XML = <dashboard displaytype={layoutManagerViewType} isfullscreen={isFullScreen}/>
			personalization.appendChild(dashboard);
			for(var i:int=0; i<manager.items.length; i++)
			{
				//Alert.show(manager.items.length.toString());
				
				//need to check whether the action is delete or add and call update or remove the widget accordingly from the personalization
				
				var widget:XML = <widget id={manager.items[i]._widgetId} name={manager.items[i].title} ismaximized={manager.items[i]._isMaximized} displayorder={manager.items[i].index}> </widget>
				if (manager.items[i].myPodContent.personalizationData !=null)
					widget.appendChild(manager.items[i].myPodContent.personalizationData);
				
				personalization.appendChild(widget);
				
				//create a xmllist to store the report details for this widget
				 
			 	//add the report details for each widget
				  
			} 
			if (Application.application.ObjConfigaration.isdebugmode.toLowerCase() == "true")
			Alert.show(personalization.toString()); 
			//Create the xml file
				//var storeXml:XML = new XML();
				
				/*
				storeXml.appendChild() //Create the layoutmaximized
				storeXml.appendChild() //Create the gridviewlistview property
				*/
			//Create the Widgets node
			/*
			  for each item in manger.items
			    create a node for widget id
			    create a node for widetname
			    create a node for widget content
			    FillWidgetContent(storeXml, pod) 
			    
			  end for
			*/					
				//Call the webservice and store it in the server	
				
			Util.setPersonalizationData(Application.application.ObjConfigaration.userid,personalization);	
		}

	}
}